-
Notifications
You must be signed in to change notification settings - Fork 106
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Add support for HTTPS proxies (available to trio/asyncio) #745
Add support for HTTPS proxies (available to trio/asyncio) #745
Conversation
Looks like we could do with a docs update here... https://www.encode.io/httpcore/proxies/ We probably want to split "Proxy SSL and HTTP Versions" into "Proxy SSL" which documents the |
Okay, so attempting to test this... I'm using Installation... $ pip install httpcore trio trustme proxy.py Use $ python -m trustme
Generated a certificate for 'localhost', '127.0.0.1', '::1'
Configure your server to use the following files:
cert=/Users/tomchristie/GitHub/encode/httpcore/server.pem
key=/Users/tomchristie/GitHub/encode/httpcore/server.key
Configure your client to use the following files:
cert=/Users/tomchristie/GitHub/encode/httpcore/client.pem Running the proxy... $ proxy --cert-file server.pem --key-file server.key Make the requests... import ssl
import trio
import httpcore
ctx = ssl.create_default_context()
ctx.load_verify_locations('client.pem')
async def main():
async with httpcore.AsyncHTTPProxy(proxy_url="http://127.0.0.1:8899/", proxy_ssl_context=ctx) as http:
response = await http.request("GET", "https://www.example.com/")
print(response)
response = await http.request("GET", "http://www.example.com/")
print(response)
trio.run(main) Fails with... [...]
ssl.SSLError: [SSL: HTTPS_PROXY_REQUEST] https proxy request (_ssl.c:992) What am I getting wrong here? |
Also, occurs to me that something we could do here would be decouple this from #732. Indicate in the CHANGELOG/docs that HTTPS proxies are only supported with |
I think problem is here: httpcore/httpcore/_async/connection.py Line 140 in f7c515c
Where you set |
Just change the proxy url scheme to https. |
We should probably merge #732 first, then go over this one. |
Wonderful thanks, tested now and all working as expected. Okay so, should we add the following error cases here?...
I'd suggest that this PR is neat and uncontentious, so let's work to getting it merged, as "Add support for HTTPS proxies (available to trio/asyncio)". Then follow up with the more awkward sync support. Remaining here is...
|
@@ -51,10 +51,33 @@ proxy = httpcore.HTTPProxy( | |||
) | |||
``` | |||
|
|||
## Proxy SSL and HTTP Versions | |||
## Proxy SSL |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These docs are really nice, thanks! 💚
Because most users do not interact with SSL contexts, we can allow this behavior to keep things as simple as possible. When using the public HTTPS proxy, for example, the user must create the default SSL context and pass it to the HTTPProxy class without any modifications or configurations.
Agree |
Co-authored-by: Tom Christie <[email protected]>
Great - No objections to this. Welcome to merge once you're also happy with it @karosis88. |
Refs #722
Related #732 (Required for sync support)
TODO
proxy_ssl_context
argument toAsyncForwardHTTPConnection
,AsyncTunnelHTTPConnection
andAsyncHTTPProxy
classes